package com.sjz.chat5;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.SeekBar;

/***
 * 当移动滑杆的时候，水平滑杆的值 跟着改变  如果最大的话，圆形进度条消失
 * 涉及到 圆形进度条 水平进度条 手动可移动的进度条
 */
public class ProgressActivity extends AppCompatActivity {
    private LinearLayout ll_progress_loading;  //圆形进度条的布局id
    private ProgressBar pb_progress_loading;    //水平进度条的id
    private SeekBar sb_progress_loading;   //手动设置的进度条的长度

    private SeekBar.OnSeekBarChangeListener onSeekBarChangeListener= new SeekBar.OnSeekBarChangeListener() {
        //滑杆移动
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            Log.e("ProgressActivity","滑杆移动");

        }
        //按下滑杆
        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            Log.e("ProgressActivity","按下滑杆");
        }
        //离开滑杆 来设置进度条
        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            Log.e("ProgressActivity","离开滑杆");
            int progress=  sb_progress_loading.getProgress();//得到手动进度条的长度
            pb_progress_loading.setProgress(progress);//水平进度条 设置改变的值
         //3. 判断水平进度条是否达到最大值
            if(progress ==sb_progress_loading.getMax() ){
               //如果达到了, 设置ll_progress_loading不可见  圆形进度条隐藏
                //ll_progress_loading.setVisibility(View.INVISIBLE); //不可见, 但占用空间
                ll_progress_loading.setVisibility(View.GONE);//不可见, 且不占用空间
            }else{
               //如果没有达到 设置ll_progress_loading显示
                ll_progress_loading.setVisibility(View.VISIBLE);
            }

        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_progress);

        ll_progress_loading = (LinearLayout) findViewById(R.id.ll_progress_loading);
        pb_progress_loading = (ProgressBar) findViewById(R.id.pb_progress_loading);
        sb_progress_loading = (SeekBar) findViewById(R.id.sb_progress_loading);

        //SeekBar是一个进度可由用户自己手动设置的进度条  移动的时候触发的事件
        sb_progress_loading.setOnSeekBarChangeListener(onSeekBarChangeListener);
    }
}